<template>
  
  <view class="goods-item">
    <!-- 左侧图片区域 -->
    <view class="goods-list-left">
      <radio :checked="item.goods_state" color="#C00000" v-if="showRadio" @click="radioChange"></radio>
      <image :src="item.goods_small_logo || defaultPic" class="goods-pic" ></image>
    </view>
    <!-- 右侧文字价格区域 -->
    <view class="goods-list-right">
      <!-- 文字区域 -->
      <view class="goods-info">{{item.goods_name}}</view>
      <!-- 价格区域 -->
      <view class="goods-box">
         <view class="goods-price">￥{{item.goods_price | tofixed}}</view>
         <uni-number-box :min="1" :value="item.goods_count" v-if="showNumberBox" @change="numChange"></uni-number-box>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name:"my-goods",
    data() {
      return {
         defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png' // 默认的空图片 
      };
    },
    props:{
      item:{
        type:Object,
        default:{}
      },
      showRadio:{
        type:Boolean,
        default:false
      },
      showNumberBox:{
        type:Boolean,
        default:false
      }
    },
    filters:{
      tofixed(num){
        return Number(num).toFixed(2)
      }
    },
    methods:{
      // 自定义事件，向父组件传值  // 更新购物车中勾选状态
      radioChange(){
        this.$emit('radio-change',{
          // 商品的 Id
               goods_id: this.item.goods_id,
               // 商品最新的勾选状态
               goods_state: !this.item.goods_state
        })
      },
      // 监听商品数量的变化
      numChange(val){
        console.log(val)
        this.$emit('num-change',{
         // 商品的 Id
              goods_id: this.item.goods_id,
          //商品的最新数量
          goods_count:val-0
        })
      },
     
    }
  }
</script>

<style lang="scss">
.goods-item {
  display: flex;
  padding: 10px 5px;
  border-bottom: 1px solid #efefef;
  .goods-list-left {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-right: 10px;
    .goods-pic {
      width: 100px;
      height: 100px;
      display: block;
    }
  }
  .goods-list-right {
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: space-between;
    .goods-box{
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .goods-info {
      font-size: 13px;
    }
    .goods-price {
      font-size: 16px;
      color: #c00000;
    }
  }
}
</style>
